package ipad.asia.controller;

import ipad.asia.dao.PunishConsumerDao;
import ipad.asia.entity.PunishConsumer;
import ipad.asia.service.PunishConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

@RestController
public class PunishConsumerController {
    @Autowired
    private PunishConsumerService punishConsumerService;
    @Autowired
    private PunishConsumerDao punishConsumerDao;
    /**
     * 获取所有的被投诉消费者，用户
     * @return
     */
    @RequestMapping("/admin/complaint/getAll")
    public List<PunishConsumer> findAll(){
        return punishConsumerService.findAll();
    }
    @RequestMapping("/admin/complaint/getById")
    public PunishConsumer findById(@RequestParam(value = "id") int id){
        return punishConsumerService.findById(id);
    }

    /**
     * 查看当前用户的所有投诉
     * @param consumerId
     * @return
     */
    @RequestMapping("/admin/complaint/getByConsumerId")
    public List<PunishConsumer> findByConsumerId(@RequestParam(value = "consumerId") int consumerId){
        return punishConsumerService.findByConsumerId(consumerId);
    }

    /**
     * 对被投诉的人做出处罚，不要轻易做出处罚，处罚一次，警告一次，第二次严重警告，第三次封号
     * @param
     */
    @RequestMapping("/admin/waring")
    public void waring(@RequestParam(value = "consumerId") int consumerId){
        punishConsumerService.waring(consumerId);
    }

    /**
     * 投诉消费者，用户
     * @param consumerId
     * @param reason
     * @param proof
     * @param reportEmail
     * @param date
     */
    @RequestMapping("/complaint/consumer")
    public void complaintConsumer(@RequestParam(value = "consumerId",required = false)int consumerId,
                                  @RequestParam(value = "consumerName",required = false)String consumerName,
                                  @RequestParam(value = "reason",required = false)String reason,
                                  @RequestParam(value = "proof",required = false)String proof,
                                  @RequestParam(value = "reportEmail",required = false)String reportEmail,
                                  @RequestParam(value = "date",required = false)LocalDateTime date){
        PunishConsumer punishConsumer=new PunishConsumer();
        punishConsumer.setConsumerId(consumerId).setProof(proof).setReason(reason)
                        .setConsumerName(consumerName).setReportEmail(reportEmail).setDate(date);
        punishConsumerService.save(punishConsumer);
    }

    @RequestMapping("/consumer/update")
    @Transactional
    public void update(@RequestParam(value = "statues",required = false) int statues,
                       @RequestParam(value = "serious",required = false)int serious,
                       @RequestParam(value = "result",required = false)String result,
                       @RequestParam(value = "id",required = false)int id){
        punishConsumerDao.update(statues, serious,result ,id);
    }
}
